<?php
namespace app\admin\validate;

use think\Validate;
use app\admin\model\FlowType as FlowTypeModel;

class FlowType extends Validate 
{
    protected $rule = [
        'name' => 'require|checTypeName'
        
    ];
    
    protected $message = [
        'name.require' => '名称不能为空！',
        'name.checTypeName' => '类型名称已存在！'
    ];
    
    public function checTypeName($value, $rule, $data) 
    {
        $where = [
            'name' => $value,
            'isvalid' => 1
        ];
        if (isset($data['id'])) {
            $where['id'] = ['neq', $data['id']];
        }
        $lists = (new FlowTypeModel())->where($where)->find();
        
        return $lists ? false : true;
    }
}
